package demo.practice.competition;

public class P5814 {

    public static void main(String[] args) {
        P5814 p5814= new P5814();
        p5814.addRungs(new int[]{1,3,5,10},2);
    }

    public int addRungs(int[] rungs, int dist) {

        if (rungs == null || rungs.length == 0)
            return 0;
        int fnu = rungs[rungs.length - 1];

        int befornu = 0;
        int res = 0;

        for (int i = 0; i < rungs.length; i++) {
            if(i==rungs.length-1 ){
                //最后一个
                if(rungs[i] - befornu > dist){
                 res+=    (rungs[i] - befornu)%dist==0? (rungs[i] - befornu)/dist-1:(rungs[i] - befornu)/dist;
                }
                break;
            }



            if (rungs[i] - befornu <= dist) {
                //正常
                befornu = rungs[i];
            } else {
                //befornu= befornu+dist;
                if (befornu + dist > rungs[i]) {
                    //补充一个就欧克
                    res++;
                    befornu = rungs[i];
                } else {
                    res++;
                    befornu = befornu + dist;
                    i--;
                }
            }
        }

        return res;

    }
}
